/*	Particle Simulator. Simulates the speed and position of particles and recalculates speed and position based on collisions. 
 *	Copyright (C) 2012 W.A. Garrett Weaver.
 *	This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *	You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *	simulate.h specifies all the needed functions to simulate a particle system
 */

#ifndef SIMULATE_H
#define SIMULATE_H

//these defines provide a more recognized way to get the dimension coordinates from an array
#define X_Comp 0
#define Y_Comp 1

#include <stdbool.h>
//include math library to take advantage of square root
#include <math.h>
//include the standard library to make use of malloc
#include <stdlib.h>

#include "particle.h"
#include "barrier.h"

/*	simulate is the function that simulates the whole system. 
 *
 *	It takes:
 *	int timeSteps that respresents the number of itereations the simulations lasts for
 *	float dt represents the duration, in seconds, of each time step
 *	float gravityX represents the acceleration, due to gravity, in the x direction
 *	float gravityY represents the acceleration, due to gravity, in the y direction
 *	particle particleArray points to an array of particles that are in the system
 *	barrier barrierArray points to an array of bariers that are in the system. 
 */
bool simulate(int timeSteps, float dt, int numberOfParticles, struct particle * particleArray, float ** particleXPositions, float ** particleYPositions, int numberOfBarriers, struct barrier * barrierArray);


/*	fillCollisionMatrix fills in two boolean, lower triangular form, matricies one for particle-particle collisions and another for particle-barrier collisions 
 *	that indicate which particles paths intersect within the time step
 *
 *	float dt indicates the length of the time step
 *	int numberOfParticles indicates the number of particles in particleArray
 *	particle particleArray is the array holding all the particles in the system
 *	int numberOfBarriers indicates the number of barriers in barrierArray
 *	barrier barrierArray contains all the barriers in the system
 */
void generateCollisionMatrix(float dt, int numberOfParticles, struct particle * particleArray, int numberOfBarriers, struct barrier * barrierArray, bool ** particleParticleCollisions, bool ** particleBarrierCollisions);


/*	findIntersectionPoint sees if an intersection exists between particleOne and particleTwo, returns true if it does and provides the intersection coordinate return false otherwise
 */
bool findParticleParticleIntersectionPoint(float dt, struct particle particleOne, struct particle particleTwo, float * intersectionPoint);

#endif
